/*
 * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
 *
 * Licensed under the Aduna BSD-style license.
 */
package edu.tju.rdfbase.store.nativerdf.config;

import edu.tju.rdfbase.store.Store;
import edu.tju.rdfbase.store.config.StoreFactory;
import edu.tju.rdfbase.store.config.StoreImplConfig;
import edu.tju.rdfbase.store.nativerdf.NativeStore;
import edu.tju.rdfbase.store.StoreConfigException;

/**
 * A {@link StoreFactory} that creates {@link NativeStore}s based on RDF
 * configuration data.
 * 
 * @author Arjohn Kampman
 */
public class NativeStoreFactory implements StoreFactory {

	/**
	 * The type of repositories that are created by this factory.
	 * 
	 * @see StoreFactory#getStoreType()
	 */
	public static final String SAIL_TYPE = "openrdf:NativeStore";

	/**
	 * Returns the Store's type: <tt>openrdf:NativeStore</tt>.
	 */
	public String getStoreType() {
		return SAIL_TYPE;
	}

	public StoreImplConfig getConfig() {
		return new NativeStoreConfig();
	}

	public Store getStore(StoreImplConfig config)
		throws StoreConfigException
	{
		if (!SAIL_TYPE.equals(config.getType())) {
			throw new StoreConfigException("Invalid Store type: " + config.getType());
		}

		NativeStore nativeStore = new NativeStore();

		if (config instanceof NativeStoreConfig) {
			NativeStoreConfig nativeConfig = (NativeStoreConfig)config;
			nativeStore.setTripleIndexes(nativeConfig.getTripleIndexes());
		}

		return nativeStore;
	}
}
